import BattleObj from "../../../logic/battle/BattleObj";
import Skill from "../../Skill";
import SkillEventTriggerType from "../../triggers/SkillEventTriggerType";
import EffectType from "../EffectType";
import IActiveEffect from "../IActiveSkillEffect";
import IPassiveSkillEffect from "../IPassiveSkillEffect";

export default class HurtEffect implements IActiveEffect, IPassiveSkillEffect {
    activeEffect(skill: Skill, attacker: BattleObj, target: BattleObj, isFirstHurtTag: number, effectParams: number[]): boolean {
        //判断是否目标是否存活
        //判断目标是否无敌状态
        //计算伤害
        let hurt = this.calc(skill, attacker, target, effectParams)

        if (hurt == 0) {
            return false;
        }
        let targets: BattleObj[] = []
        //计算是否有伤害连接(比如术士的连接技能)
        targets.push(target)

        targets.forEach(t => {
            let isDead = t.isDead;
            let finallyChangeHp = t.changeHp(hurt, attacker, skill, true, EffectType.Hurt)
            if (!isDead && t.id === target.id) {//没死且和技能的目标一致，则触发被攻击事件
                // 派发被攻击事件
                t.eventDispatcher.emit(SkillEventTriggerType.BeAttackAfter, attacker, skill, isFirstHurtTag == 0, finallyChangeHp)
                t.room.eventDispatcher.emit(SkillEventTriggerType.BeAttackAfter, attacker, target, skill, finallyChangeHp);

                attacker.eventDispatcher.emit(SkillEventTriggerType.AttackAfter, t, skill, isFirstHurtTag == 0, finallyChangeHp);
            }
        })

        return true;
    }
    //根据伤害公式计算伤害
    calc(skill: Skill, attacker: BattleObj, target: BattleObj, effectParams: number[]) {
        
        return 0;
    }

    passiveEffect(passiveSkillId: number, skill: Skill, attacker: BattleObj, target: BattleObj, times: number, effectParams: number[], condtition: number[]): boolean {
        return true;
    }

}